/**
 *    Copyright 2006-2016 the original author or authors.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package org.amado.generator.plugins;

import java.util.List;
import java.util.Properties;

import org.amado.generator.util.DateUtil;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.PluginAdapter;
import org.mybatis.generator.api.dom.java.Interface;
import org.mybatis.generator.api.dom.java.TopLevelClass;


/**
 * This plugin adds the java.io.Serializable marker interface to all generated
 * model objects.
 * <p>
 * This plugin demonstrates adding capabilities to generated Java artifacts, and
 * shows the proper way to add imports to a compilation unit.
 * <p>
 * Important: This is a simplistic implementation of serializable and does not
 * attempt to do any versioning of classes.
 * 
 * @author Jeff Butler
 * 
 */
public class CommentPlugin extends PluginAdapter {
    private String author;
	@Override
	public boolean validate(List<String> warnings) {
		return true;
	}
	@Override
    public void setProperties(Properties properties) {
        super.setProperties(properties); 
        author = properties.getProperty("author"); //$NON-NLS-1$
    }
    @Override
	public boolean clientGenerated(Interface interfaze, TopLevelClass topLevelClass,
			IntrospectedTable introspectedTable) {
		super.clientGenerated(interfaze, topLevelClass, introspectedTable);
		interfaze.addJavaDocLine("/**"); //$NON-NLS-1$
		/**
		 * TODO
		 * @author wangyulong-910
		 * @date 2017年5月26日下午4:14:33
		 */
		String remarks = introspectedTable.getRemarks();
		String[] remarkLines = remarks.split(System.getProperty("line.separator")); //$NON-NLS-1$
		for (String remarkLine : remarkLines) {
			interfaze.addJavaDocLine(" * " + remarkLine); //$NON-NLS-1$
			}
		interfaze.addJavaDocLine(" * @author " + author); //$NON-NLS-1$
		interfaze.addJavaDocLine(" * @date " + DateUtil.getDateStr()); //$NON-NLS-1$
		interfaze.addJavaDocLine(" */"); //$NON-NLS-1$
		return true;
	}
}
